import EventDispatcher from "./EventDispatcher";
import TSMap from "../math/TSMap";

export default class EventProxy {


    private dispatcher:EventDispatcher;
    private eventMap:TSMap;
    constructor(){
        this.eventMap = new TSMap();
    }
    setDispatcher(dispatcher:EventDispatcher){
        this.dispatcher = dispatcher;
    }
    addEventListener(eventName,func:Function,target:Object){
        if(!this.eventMap.get(eventName)){
            this.dispatcher.addEventListener(eventName,func,target);
            this.eventMap.set(eventName,{eventName:eventName,target:target,func:func});
        }
    }
    hasEventListener(eventName){
        return this.eventMap.has(eventName);
    }
    removeAllEventListener(){
        if(this.dispatcher){
            this.eventMap.forEach(element => {
                this.dispatcher.removeEventListener(element.eventName,element.func,element.target);  
            })
            this.eventMap.clear();
        }

    }
}
